package com.java.rabbitmq.consumer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Woo_home
 * @create 2020/5/28 21:08
 */

@Configuration
public class BlogConfig {

    @Bean
    public TopicExchange blogExchange() {
        return new TopicExchange("BlogExchange");
    }

    @Bean
    public Queue blogJavaQueue() {
        return new Queue("BlogQueue", true);
    }

    @Bean
    public Queue blogJavaNotQueue() {
        return new Queue("BlogDotNetQueue", true);
    }

    @Bean
    public Queue blogAllQueue() {
        return new Queue("BlogAllQueue", true);
    }

    @Bean
    public Binding bindingToJavaQueue() {
        return BindingBuilder.bind(blogJavaQueue())
                .to(blogExchange())
                .with("blog.java");
    }

    @Bean
    public Binding bindingToDotNetQueue() {
        return BindingBuilder.bind(blogJavaNotQueue())
                .to(blogExchange())
                .with("blog.doNet");
    }

    @Bean
    public Binding bindingToAllQueue() {
        return BindingBuilder.bind(blogAllQueue())
                .to(blogExchange())
                // 表示只要是 blog 开头的即可
                .with("blog.#");
    }
}
